/*----------------------------------------------------------------------------
 * os_obj.h: CMSIS-RTOS global object definitions for an application
 *----------------------------------------------------------------------------
 *
 * This header file defines global RTOS objects used throughout a project
 *
 * #define osObjectsPublic indicates that objects are defined; without that
 * definition the objects are defined as external symbols.
 *
 *--------------------------------------------------------------------------*/


#ifndef __os_obj__
#define __os_obj__


#ifdef __os_obj_creat__
#define OBJ_EXT
#else
#define OBJ_EXT extern
#endif

#include  <rtthread.h>
#include <rtconfig.h>
#include <cmsis_rt.h>
#include "sys_ext.h"

#define ms_ticks(x)        (x*RT_TICK_PER_SECOND/1000)

#define PRIO_BELOW_LOW         (RT_THREAD_PRIORITY_MAX-5)
#define PRIO_LOW               (PRIO_BELOW_LOW-1)
#define PRIO_ABOVE_LOW         (PRIO_LOW-1)
#define PRIO_BELOW_MIDDLE      (PRIO_ABOVE_LOW-1)
#define PRIO_MIDDLE            (PRIO_BELOW_MIDDLE-1)
#define PRIO_ABOVE_MIDDLE      (PRIO_MIDDLE-1)
#define PRIO_BELOW_HIGH        (PRIO_ABOVE_MIDDLE-1)
#define PRIO_HIGH              (PRIO_BELOW_HIGH-1)
#define PRIO_ABOVE_HIGH        (PRIO_HIGH-1)
#define PRIO_REAL              (2)

#if (PRIO_ABOVE_HIGH <= 2) || (PRIO_ABOVE_HIGH >= RT_THREAD_PRIORITY_MAX) || (PRIO_BELOW_LOW >= RT_THREAD_PRIORITY_MAX)
#error TASK_PRIOTITY ERROR @ osOObjCreat.h file ...
#endif

// global 'thread' functions ---------------------------------------------------
#define  STK_SIZE(x)                             (x*4)


int os_thread_init (void);
int os_obj_create (void);

void           LedCtrTask               (void  *p_arg);
void           SwTestTask               (void  *p_arg);
void SysTask(void *p_arg);
void TestTask(void *p_arg);
void FileTask(void *p_arg);
void SdEventTask(void *p_arg);
void GuiTask(void *p_arg);
void q25_task(void *p_arg);
void           ComTask                  (void  *p_arg);
void     HisDataTask                             (void *argument);
void           ModbusTask               (void  *p_arg);
void           StorageTask               (void  *p_arg);
void ComCmdTask(void *argument);

typedef struct
{
#define  TASK_LEDCTR_STK_SIZE                    STK_SIZE(0x200)
#define  TASK_LEDCTR_PRIO                        PRIO_LOW
    rt_thread_t  tid_LedCtrTask;

#define  SYS_TASK_STK_SIZE                       STK_SIZE(0x4000)
#define  SYS_TASK_PRIO                           PRIO_REAL
    rt_thread_t  tid_SysTask;

#define  FILE_TASK_STK_SIZE                       STK_SIZE(0x1000)
#define  FILE_TASK_PRIO                           PRIO_LOW
    rt_thread_t  tid_FileTask;
    
#define  SD_EVT_TASK_STK_SIZE                     STK_SIZE(0x200)
#define  SD_EVT_TASK_PRIO                         PRIO_BELOW_MIDDLE
    rt_thread_t  tid_SD_EventTask;
    
#define  GUI_TASK_STK_SIZE                       STK_SIZE(0x4000)
#define  GUI_TASK_PRIO                           PRIO_LOW
    rt_thread_t tid_GuiTask;

#define  Q25_TASK_STK_SIZE                       STK_SIZE(0x1000)
#define  Q25_TASK_PRIO                           PRIO_MIDDLE
    rt_thread_t tid_Q25Task;

#define  TASK_COM_STK_SIZE                       STK_SIZE(0x400)
#define  TASK_COM_PRIO                           PRIO_MIDDLE
    rt_thread_t  tid_ComTask;

#define  HIST_TASK_STK_SIZE                       STK_SIZE(0x400)
#define  HIST_TASK_PRIO                           PRIO_LOW
    rt_thread_t tid_HistTask;

#define  TASK_MODBUS_STK_SIZE                    STK_SIZE(0x400)
#define  TASK_MODBUS_PRIO                        PRIO_BELOW_HIGH
    rt_thread_t  tid_ModbusTask;

#define  TASK_STORAGE_STK_SIZE                    STK_SIZE(0x400)
#define  TASK_STORAGE_PRIO                        PRIO_LOW
    rt_thread_t  tid_StorageTask;

#define  TASK_COM_CMD_STK_SIZE                    STK_SIZE(0x400)
#define  TASK_COM_CMD_PRIO                        PRIO_BELOW_MIDDLE
    rt_thread_t  tid_ComCmd;
    
	rt_thread_t  tid_touch;
	
// global enent-groups object  ------------------------------------------
    rt_event_t           eid_modbus;
    rt_event_t           eid_com;
// global sem object  -------------------------------------------------
    rt_sem_t             sid_SwTest;
    

// global mutex object  -------------------------------------------------

    rt_mutex_t            mid_malloc;
    rt_mutex_t            mid_spiflash;

// global message queue object  -----------------------------------------

// global mail box object     -------------------------------------------
//    rt_mailbox_t          mbid_modbus;
    rt_mailbox_t         qbid_flash;
    rt_mailbox_t         qbid_SD_event;
    
} os_obj_type;

OBJ_SRAM OBJ_EXT os_obj_type   os_obj;


#endif  // __os_obj__
